#include "CSplashState.h"
#include "CGame.h"
#include "CFont.h"
#include "CMainMenuState.h"
#include "SGD Wrappers/CSGD_TextureManager.h"
#include "SGD Wrappers/CSGD_Direct3D.h"
#include "SGD Wrappers/CSGD_DirectInput.h"
#include <windows.h>
#include "CAnimationEngine.h"
#include "CAnimationInfo.h"


CSplashState* CSplashState::m_nInstance = NULL;

CSplashState::CSplashState(void)
{
}

CSplashState::~CSplashState(void)
{
}

void CSplashState::Enter(void)
{
	Font.load();
	m_nLogoID = CSGD_TextureManager::GetInstance()->LoadTexture("resource/graphics/scglogo.png");
	char tempChar[5] = "Test";
	testing.SetAnimation(tempChar);
	testing.SetCurFrame(0);
	testing.SetPlaying(true);
	testing.SetTimer(0.0f);
}

bool CSplashState::Input(void)
{
	if(CSGD_DirectInput::GetInstance()->KeyPressed(CSGD_DirectInput::GetInstance()->GetDIKCode()))
	{
		CGame::GetInstance()->ChangeState(CMainMenuState::GetInstance());
	}

	return true;
}

void CSplashState::Update(float fElapsedTime)
{
	CAnimationEngine::GetInstance()->Update(testing, fElapsedTime);
}

void CSplashState::Render(void)
{
	//CSGD_Direct3D::GetInstance()->DeviceBegin();
	//CSGD_Direct3D::GetInstance()->SpriteBegin();
	//CSGD_Direct3D::GetInstance()->LineBegin();

	RECT tempRect;
	tempRect.top = 0;
	tempRect.left = 0;
	tempRect.right = 150;
	tempRect.bottom = 187;

	CSGD_TextureManager::GetInstance()->Draw(m_nLogoID, 245, 226, 1, 1, &tempRect);
	CAnimationEngine::GetInstance()->Render(testing.GetAnimation(), testing.GetCurFrame(), 100, 100, 1, 1);


//	CSGD_Direct3D::GetInstance()->LineEnd();
//	CSGD_Direct3D::GetInstance()->SpriteEnd();
//	CSGD_Direct3D::GetInstance()->DeviceEnd();
}

void CSplashState::Exit(void)
{
	if(m_nInstance)
	{
		delete m_nInstance;
		m_nInstance=NULL;
	}
}


CSplashState* CSplashState::GetInstance()
{
	if(m_nInstance == NULL)
	{
		m_nInstance = new CSplashState();
	}
	return m_nInstance;
}